unit CheckBill;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, Dialogs, uniGUITypes, uniGUIAbstractClasses,
  uniGUIClasses, uniGUIFrame, DB, uniBasicGrid, uniDBGrid, uniButton, uniBitBtn,
  uniGUIBaseClasses, uniPanel, uniCheckBox, uniRadioButton, uniEdit, uniLabel,
  DBClient, ClientRowSet;

type
  TFrmCheckBill = class(TUniFrame)
    UniPanel1: TUniPanel;
    btCkFee: TUniBitBtn;
    GridBill: TUniDBGrid;
    dsBill: TDataSource;
    btFind: TUniBitBtn;
    ckFee: TUniRadioButton;
    ckCOD: TUniRadioButton;
    ckAll: TUniRadioButton;
    UniLabel1: TUniLabel;
    edBillNo: TUniEdit;
    procedure btCkFeeClick(Sender: TObject);
    procedure ckCODClick(Sender: TObject);
    procedure ckAllClick(Sender: TObject);
    procedure ckFeeClick(Sender: TObject);
    procedure btFindClick(Sender: TObject);
    procedure edBillNoKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure ShowAllUnCheckData;
    procedure ShowUnCheckCOD;
    procedure ShowUnCheckFee;
  end;

implementation

{$R *.dfm}

uses accmodule;

procedure TFrmCheckBill.btCkFeeClick(Sender: TObject);
var
  version:Integer;
begin
  dsBill.DataSet.Edit;
  if ckFee.Checked then
  begin
    dsBill.DataSet.FieldByName('ck_fee').AsInteger := 1;
    dsBill.DataSet.FieldByName('checkfee').AsBoolean := True;
  end;

  if ckCOD.Checked then
  begin
    dsBill.DataSet.FieldByName('ck_cod').AsInteger := 1;
    dsBill.DataSet.FieldByName('CHECKOCD').AsBoolean := True;
  end;

  if ckAll.Checked then
  begin
    dsBill.DataSet.FieldByName('checkfee').AsBoolean := True;
    dsBill.DataSet.FieldByName('CHECKOCD').AsBoolean := True;
    dsBill.DataSet.FieldByName('ck_fee').AsInteger := 1;
    dsBill.DataSet.FieldByName('ck_cod').AsInteger := 1;
  end;

  version := dsBill.DataSet.FieldByName('version').AsInteger;
  dsBill.DataSet.FieldByName('version').AsInteger := version + 1;
  TClientRowset(dsBill.DataSet).ApplyUpdates;

end;

procedure TFrmCheckBill.ckAllClick(Sender: TObject);
begin
  self.ShowAllUnCheckData;
end;

procedure TFrmCheckBill.ckCODClick(Sender: TObject);
begin
  ShowUnCheckCOD;
end;

procedure TFrmCheckBill.ckFeeClick(Sender: TObject);
begin
  ShowUnCheckFee;
end;

procedure TFrmCheckBill.edBillNoKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key = 13 then btfind.Click;
end;

procedure TFrmCheckBill.ShowAllUnCheckData;
var
  condition: String;
  I: Integer;
begin
  condition := '(ck_fee=0 or (ck_cod=0 and ocd>0))';
  dmAcc.ShowUnCheckBills(condition);
  for I := 0 to GridBill.Columns.Count - 1 do
    GridBill.Columns[I].Visible := True;

end;

procedure TFrmCheckBill.ShowUnCheckCOD;
var
  condition: String;
  I: Integer;
begin
  condition := '(ck_cod=0 and ocd>0)';
  dmAcc.ShowUnCheckBills(condition);
  for I := 0 to GridBill.Columns.Count - 1 do
  begin
    GridBill.Columns[I].Visible := True;
  end;
  GridBill.Columns[6].Visible := False;
  GridBill.Columns[7].Visible := False;
  GridBill.Columns[8].Visible := False;
  GridBill.Columns[9].Visible := False;

end;

procedure TFrmCheckBill.ShowUnCheckFee;
var
  condition: String;
  I: Integer;
begin
  condition := '(ck_fee=0)';
  dmAcc.ShowUnCheckBills(condition);
  for I := 0 to GridBill.Columns.Count - 1 do
  begin
    GridBill.Columns[I].Visible := True;
  end;
  GridBill.Columns[10].Visible := False;
  GridBill.Columns[11].Visible := False;
end;

procedure TFrmCheckBill.btFindClick(Sender: TObject);
begin
  if edbillno.Text <> '' then
    dsBill.DataSet.Filter := 'bill_no like ' + quotedstr(edbillno.Text+'%')
  else
    dsBill.DataSet.Filter := '';


end;

end.
